﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Negocio;
using Dominio;
using System.Web.UI.WebControls;

public partial class DisciplinaInserir : System.Web.UI.Page
{
    DisciplinaVO vo;
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.QueryString.Count != 0) && (!IsPostBack))
        {
            vo = DisciplinaNegocio.findByPrimaryKey(Convert.ToInt32(Request.QueryString["id"]));
            this.objetoToForm(vo);
        }
    }

    private void objetoToForm(DisciplinaVO disciplina)
    {
        lblID.Text = disciplina.id.ToString();
        txtNome.Text = disciplina.Nome;
    }

    private void formToObjecto()
    {
        if (vo == null)
            vo = new DisciplinaVO();

        try
        {
            vo.id = Convert.ToInt32(lblID.Text);
        }
        catch (Exception)
        {
            vo.id = 0;
        }
        vo.Nome = txtNome.Text;
        
    }



    protected void Button1_Click(object sender, EventArgs e)
    {
        this.formToObjecto();
        DisciplinaNegocio.salvar(vo);        
        Response.Redirect("Disciplina.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Disciplina.aspx");
    }
}